package com.cd.hospital.www.web;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cd.hospital.modules.entity.FriendLinkEntity;
import com.cd.hospital.modules.service.FriendLinkService;
import com.cd.hospital.common.utils.PageUtils;
import com.cd.hospital.common.utils.Query;
import com.cd.hospital.common.utils.R;




/**
 * 
 * 
 * @author weirdor
 * @email 179946422@qq.com
 * @date 2017-09-18 21:15:52
 */
@RestController
@RequestMapping("/modules/friendlink")
public class FriendLinkController extends AbstractController {
	@Autowired
	private FriendLinkService friendLinkService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("modules:friendlink:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<FriendLinkEntity> friendLinkList = friendLinkService.queryList(query);
		int total = friendLinkService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(friendLinkList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{linkId}")
	@RequiresPermissions("modules:friendlink:info")
	public R info(@PathVariable("linkId") Integer linkId){
		FriendLinkEntity friendLink = friendLinkService.queryObject(linkId);
		
		return R.ok().put("friendLink", friendLink);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("modules:friendlink:save")
	public R save(@RequestBody FriendLinkEntity friendLink){
		friendLinkService.save(friendLink);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("modules:friendlink:update")
	public R update(@RequestBody FriendLinkEntity friendLink){
		friendLinkService.update(friendLink);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("modules:friendlink:delete")
	public R delete(@RequestBody Integer[] linkIds){
		friendLinkService.deleteBatch(linkIds);
		
		return R.ok();
	}
	
}
